
// 通过Promise对ajax进行了二次封装  请求接口 返回请求成功的数据 
// url    请求的接口地址
// params 传递的数据(对象类型)
// type    请求方式 (默认get)
// 返回值 进行中状态的Promise实例

function request(url, params = {}, type = "get") {
    return new Promise(function (resolve, reject) {
        // if ($) {
        //     var { ajax } = $;
        // }
        $.ajax({
            type: type,
            url: url,
            data: {
                ...params
            },
            dataType: "json",
            success: function (result) {
                resolve(result);  // 如果请求成功, 传递请求的数据
            }
        })
    })
}

// 注册
const isExistUser = params => request("../php/isExistUser.php", params, "post");
// const isExistPhone = params => request("../php/isExistPhone.php", params, "post");
const register = params => request("../php/register.php", params, "post");

// 登录
const login = params => request("../php/login.php", params, "post");

// 主页面
const searchOrderLimit = params => request("../php/searchOrderLimit.php", params, "get");
const deleteGradeById = params => request("../php/deleteGradeById.php", params);
const searchGradeById = params => request("../php/searchGradeById.php", params);
const updateGradeById = params => request("../php/updateGradeById.php", params, "post");

// const addToShoppingCar = params => request("../php/addToShoppingCar.php", params, "post");

// 商品列表
const searchAllGoods = params => request("../php/searchAllGoods.php", params);
const searchGoodsById = params => request("../php/searchGoodsById.php", params);

const addShoppingCar = params => request("../php/addShoppingCar.php", params, "post");

// 购物车
const searchShoppingByUser = params => request("../php/searchShoppingByUser.php", params, "post");
const deleteShoppingCarById = params => request("../php/deleteShoppingCarById.php", params);